using Microsoft.AspNetCore.SignalR.Client;
using qYun.Shared.Models;
using qYun.Web;
using qYun.Web.Components;

var builder = WebApplication.CreateBuilder(args);

// Add service defaults & Aspire components.
builder.AddServiceDefaults();

// Add services to the container.
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents();

builder.Services.AddOutputCache();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddCors(options => 
    options.AddPolicy("AllowBlazor",builder=>
        builder.AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader()
        )
    );
builder.Services.AddSignalR();  // 服务器端 SignalR 支持
builder.Services.AddSingleton<HubConnectionBuilder>();  // 客户端连接构建器
builder.Services.AddHttpClient(); // 注册 HttpClientFactory


var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();
app.UseAntiforgery();

app.UseOutputCache();

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode();

app.MapDefaultEndpoints();
app.MapHub<DataHub>("/update");

app.Run();
